package com.zhaodui.util;


import com.zhaodui.jdwx.jdwxController;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.system.sms.service.TSSmsServiceI;
import org.jeecgframework.web.system.sms.util.MailUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 
 * @ClassName:SmsSendTask 所有信息的发送定时任务类
 * @Description: TODO
 * @author Comsys-skyCc cmzcheng@gmail.com
 * @date 2014-11-13 下午5:06:34
 * 
 */

@Service("emailTask")
public class EmailTask implements Job{

	@Autowired
	private TSSmsServiceI tSSmsService;
	@Autowired
	private SystemService systemService;
	/*@Scheduled(cron="0 0/1 * * * ?")*/
	public void run() {
		long start = System.currentTimeMillis();
		org.jeecgframework.core.util.LogUtil.info("===================推送Email消息定时任务开始===================");
		try {
//			tSSmsService.send();


//			if(sysmailList==null || sysmailList.size()==0){
//				return;
//			}else {
//				String sendtype = ResourceUtil.getConfigByName("sendtype");
//				for (int i = 0; i < sysmailList.size(); i++) {
//					FxjSysMailEntity mailEntity = sysmailList.get(i);
//					 try {
//						 String smtpHost= ResourceUtil.getConfigByName("mail.smtpHost");
//						 String receiver = mailEntity.getMailToaddr();
//						 String title = mailEntity.getMailSubject();
//						 String content = mailEntity.getMailMessage();
//						 String sender = ResourceUtil.getConfigByName("mail.sender");
//						 String user = ResourceUtil.getConfigByName("mail.user");
//						 String pwd = ResourceUtil.getConfigByName("mail.pwd");
//						 if(sendtype.equals("sms")){
//							 com.zhaodui.jdwx.jdwxController jdwx = new jdwxController();
//							 HttpServletRequest request = null;
//							 jdwx.dosms(receiver,content,request);
//						 }else{
//							 MailUtil.sendEmail(smtpHost, receiver,
//									 title, content, sender, user,  pwd);
//						 }
//
//						 mailEntity.setMailStatus("发送成功");
//						 systemService.saveOrUpdate(mailEntity);
//					 }catch (Exception e){
//						 mailEntity.setUpdateName("system");
//						 systemService.saveOrUpdate(mailEntity);
//					 }
//				}
//			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		org.jeecgframework.core.util.LogUtil.info("===================推送Email定时任务结束===================");
		long end = System.currentTimeMillis();
		long times = end - start;
		org.jeecgframework.core.util.LogUtil.info("总耗时"+times+"毫秒");
	}

	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		run();
	}
}
